<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
// import resize from "./mixins/resize";
export default {
  // mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "400px",
    },
    selJobWantedJobList: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  // created() {
  //   this.initChart();
  // },
  computed: {
    // 职位分布
    selJobWantedJobType() {
      return this.selJobWantedJobList.map((item) => item.type);
    },
    // 男
    selJobWantedJobMen() {
      return this.selJobWantedJobList.map((item) => item.menCount);
    },
    // 女
    selJobWantedJobWomen() {
      return this.selJobWantedJobList.map((item) => item.womenCount);
    },
  },
  watch: {
    selJobWantedJobList(newVal, oldVal) {
      if (newVal.length > 0) {
        this.initChart();
      }
    },
  },
  mounted() {
    this.initChart();
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
      const that = this;
      this.chart.setOption({
        title: {
          text: "求职者职类性别分布TOP20",
          left: "",
          textStyle: {
            color: "#333", // 字体颜色设置为黑色
            fontWeight: "bold", // 加粗字体
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        legend: {
          data: ["男", "女"],
          top: 30,
        },
        xAxis: {
          type: "category",
          data: this.selJobWantedJobType,
          axisLabel: {
            interval: 0,
            rotate: 45,
          },
          axisLabel: {
            color: "#333",
          },
        },
        yAxis: {
          type: "value",
          max: 400,
          axisLabel: {
            color: "#333",
          },
        },
        series: [
          {
            name: "男",
            type: "bar",
            data: this.selJobWantedJobMen,
            itemStyle: { color: "#48a1fd" },
          },
          {
            name: "女",
            type: "bar",
            data: this.selJobWantedJobWomen,
            itemStyle: { color: "#f0637b" },
          },
        ],
      });
    },
  },
};
</script>

<style scoped></style>
